package org.ricks.gateway.cluster.transport;

import io.scalecube.cluster.transport.api.JdkMessageCodec;
import io.scalecube.cluster.transport.api.Message;
import org.ricks.net.extension.protocol.FixedLengthBytesProtocol;
import org.ricks.net.transport.AioSession;

import java.io.ByteArrayInputStream;


// 协议实现
public class SmartSocketProtocol extends FixedLengthBytesProtocol<Message> {

    @Override
    protected Message decode(byte[] bytes, AioSession session) {
        ByteArrayInputStream outputStream = new ByteArrayInputStream(bytes);
        try {
            return JdkMessageCodec.INSTANCE.deserialize( outputStream);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
